home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 518 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: news.sprintlink.net!datalytics!news
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: beginner question - typecasting
  5. Date: 4 Jan 1996 21:30:19 GMT
  6. Organization: Datalytics, Inc
  7. Message-ID: <4chgtb$ldg@gold.datalytics.com>
  8. References: <4cei1r$s02@sun.cis.smu.edu> <30EBCED7.774@sto.fdata.se>
  9. NNTP-Posting-Host: pc071.datalytics.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
  14.  
  15. Niklas Mellin <niklas.mellin@sto.fdata.se> wrote:
  16. >Damon Bowman wrote:
  17. >> 
  18. >> When you are typecasting, is there any difference between:
  19. >> 
  20. >> a = int(x)
  21. >> and
  22. >> a = (int) x
  23. >
  24. >[...]
  25. >
  26. >Yes the first is not type casting, but a "type conversion".
  27.  
  28. No.  The two are the same in effect.  The difference in syntax 
  29. allows for some changes introduced in C++'s syntax.  I don't 
  30. recall now the eact reason for the new syntax.
  31.  
  32. >When x is a  variables of built in types there is no
  33. >difference. But if x is a varible of some class for instance
  34. >the first form generates a call to that class' operator int(),
  35. >generating a compile time error message if there is no such
  36. >member function.
  37.  
  38. There is no difference in behavior.
  39.  
  40. >The 2nd form is an inheritance from plain C, and doesn't work
  41. >when x is of class type. It is also
  42. >not "safe", meaning that the compiler will not generate error
  43. >messages in certain situations, and you will get buggy code
  44. >or run time errors instead.
  45.  
  46. Not at all correct.
  47.  
  48. >
  49. [snip]
  50.  
  51.  
  52. -- 
  53. Robert Stewart        | My opinions are usually my own.
  54. Datalytics, Inc.
  55. (513)226-7700
  56. stew@datalytics.com
  57.  
  58.  
  59.